package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.StrategyCollection;
import cn.wolfcode.trip.base.query.TravelCollectionQuery;
import cn.wolfcode.trip.base.service.IStrategyCollectionService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("strategyCollection")
public class StrategyCollectionController {
    @Autowired
    private IStrategyCollectionService strategyCollectionService;

    @RequestMapping("/save")
    public JSONResult save(Long userId,Long strategyId){
        JSONResult result = new JSONResult();
        try {
            strategyCollectionService.save(userId,strategyId);
        } catch (Exception e) {
            result.mark(e.getMessage());
        }
        return result;
    }

    @RequestMapping("/get")
    public JSONResult get(Long userId, Long strategyId){
        JSONResult result = new JSONResult();
        try {
            StrategyCollection strategyCollection = strategyCollectionService.get(userId, strategyId);
            if (strategyCollection==null){
                result.mark("不存在");
            }
        } catch (Exception e) {
            result.mark(e.getMessage());
        }
        return result;
    }


    @RequestMapping("/list")
    public Object list(@ModelAttribute("qo")TravelCollectionQuery qo, Model model){

        return strategyCollectionService.list(qo);
    }


    @RequestMapping("/delete")
    public JSONResult delete(Long userId,Long strategyId){
        JSONResult result = new JSONResult();
        try {
            strategyCollectionService.delete(userId,strategyId);
        } catch (Exception e) {
            result.mark(e.getMessage());
        }
        return result;
    }

}
